﻿/**
* @author alex
*/
Namespace("sketch.framework.text");

(function ($) {
    var txt = sketch.framework.text,
        fwk = sketch.framework;
    txt.InplaceEditor = klass(null, {
        _constructor:function(/*VisualTree*/visualTree, /*bool*/multiLine){
            this.parent = visualTree;
            this.multiLine = multiLine;

            if(this.multiLine){
                this.element = document.createElement("textarea");
            }else{
                this.element = document.createElement("input");
                this.element.setAttribute("type", "text");
            }
            var $element = $(this.element);
            $element.bind("mousedown", function(event){                
                event.stopPropagation();
            });
        },
        show:function(/*str*/text, /*int*/x, /*int*/y, /*int*/width, /*int*/height){
            var style = "position:absolute;left:"+x+"px";
            style += ";top:" + y + "px";
            style += ";width:"+ width + "px";
            style += ";height:" + height + "px";
            this.element.setAttribute("style", style);
            if(this.multiLine){
                this.element.value = text;
            }

            this.parent.view().addHtmlElement(this.element);
        },
        hide:function(){            
            this.parent.view().removeHtmlElement(this.element);
        },
        value:function(){
            if(this.multiLine){
                return this.element.value;
            }
        }
    });
})(jQuery);